package com.fjeld.swingx.table;

import com.fjeld.client.gui.util.factories.LabelFactory;
import com.fjeld.swingx.ColorConstants;
import com.fjeld.swingx.JGradientPanel;

import static com.fjeld.swingx.ColorConstants.*;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: fjeld
 * Date: 28/12/2011
 * Time: 14:42
 *
 * Renders a cell transparent
 */
public class HeaderCellRenderer extends JGradientPanel implements TableCellRenderer
{
    private JLabel label = LabelFactory.createTableHeaderLabel("");
    public HeaderCellRenderer()
    {
        super(INFORBAR_BOTTOM_LINE, INFOBAR_BOTTOM_GRADIENT, INFORBAR_BOTTOM_LINE,
                INFOBAR_TOP_GRADIENT, INFOBAR_LIGHT_LINE);
        Border air = BorderFactory.createEmptyBorder(2,2,2,2);
        Border darkLine = BorderFactory.createMatteBorder(0, 0, 1, 0, INFORBAR_BOTTOM_LINE);
        Border inner2 = BorderFactory.createCompoundBorder(darkLine, air);

        Border topDarkLine = BorderFactory.createMatteBorder(1, 1, 0, 0, INFOBAR_DIVIDER_DARK_LINE);
        Border topLightLine = BorderFactory.createMatteBorder(1, 1, 0, 0, INFOBAR_LIGHT_LINE);
        Border topDividerLine = BorderFactory.createCompoundBorder(topDarkLine, topLightLine);

        setBorder(BorderFactory.createCompoundBorder(topDividerLine, inner2));
        this.add(label, BorderLayout.CENTER);
    }

    public Component getTableCellRendererComponent(JTable jTable, Object value,
                                                   boolean isSelected, boolean hasFocus, int row, int column)
    {
        label.setText(null != value ? value.toString() : "");
        return this;
    }
}
